<?php

class Sharepoint
{
    var $host = "http://192.168.1.1:2012/sites/Test/_vti_bin/ListData.svc/";
    var $mError = '';

    function _processCurl($url, $credentials)
    {
        $ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
        curl_setopt($ch, CURLOPT_USERPWD, $credentials);
        curl_setopt($ch, CURLOPT_PROXY, "http://192.168.4.102:4044");
        curl_setopt($ch, CURLOPT_PROXYPORT, 4044);
	$data = curl_exec($ch);
        curl_close($ch);

        try
        {
            $results = new SimpleXmlElement($data, LIBXML_NOCDATA);
        }
        catch(Exception $ex)
        {
            return -1;
        }
        
        return $results;
    }

    public function GetListData($list_name, $creds)
    {
        if('' == $list_name)
        {
            $this->mError = "Query is blank";
            return false;
	}

        $url = $this->host . $list_name;

        $results = $this->_processCurl($url, $creds);

        return $results;
    }
    
    public function VerifyCredentials($login_url, $creds)
    {
        if('' == $creds)
        {
            $this->mError = "Blank Credentials";
            return false;
	}

        $result = $this->_processCurl($login_url, $creds);

        return $result;
    }

    function GetError()
    {
	return $this->mError;
    }
}
?>
